<%@ page language="java" contentType="text/html; charset=UTF-8"
         pageEncoding="UTF-8" %>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ page isELIgnored="false" %>
<jsp:include page="../../include/top.jsp"/>
<div class="main_body">
    <div class="span9 page_message">
        <section id="contents">
            <ul class="tab-nav nav">
                <li><a href="${BasePath}/order/order/list?${PublicParams}">订单列表<span
                        class="arrow fa fa-sort-up"></span></a></li>
                <li class="current"><a href="">订单添加/修改<span class="arrow fa fa-sort-up"></span></a></li>
            </ul>
            <div class="tab-content">
                <div id="tab1" class="tab-pane in tab1">
                    <!-- 表单 -->
                    <form name="myForm" id="myForm" action="${BasePath}/order/order/save" method="post">

                        <input type="hidden" name="id" value="${bean.id }"/>
                        <input type="hidden" name="type" value="${type }"/>
                        <input type="hidden" name="itemId" value="${itemId }"/>

                        <div class="form-item cf toggle-groupName">
                            <label class="item-label">
                                <span class="need_flag">*</span>
                                订单来源：
                                <span class="check-tips"></span>
                            </label>

                            <div class="controls">
                                <select id="orderFrom" name="orderFrom">
                                    <option value="电话"
                                            <c:if test="${bean.orderFrom=='电话'}">selected="selected" </c:if> >电话
                                    </option>
                                    <option value="网站"
                                            <c:if test="${bean.orderFrom=='网站'}">selected="selected" </c:if> >网站
                                    </option>
                                    <option value="员工自购"
                                            <c:if test="${bean.orderFrom=='员工自购'}">selected="selected" </c:if> >员工自购
                                    </option>
                                </select>
                            </div>
                        </div>
                        <div class="form-item cf toggle-orderFrom">
                            <label class="item-label">
                                <span class="need_flag">*</span>
                                购买人：
                                <span class="check-tips"></span>
                            </label>

                            <div class="controls">
                                <input class="input-xlarge focused" id="buyUser" name="buyUser" type="text" value="${bean.buyUser}" required>
                            </div>
                        </div>
                        <div class="form-item cf toggle-orderFrom">
                            <label class="item-label">
                                <span class="need_flag">*</span>
                                体检人：
                                <span class="check-tips"></span>
                            </label>

                            <div class="controls">
                                <input class="input-xlarge focused" id="endUser" name="endUser" type="text" value="${bean.endUser}" required>
                            </div>
                        </div>
                        <div class="form-item cf toggle-orderFrom">
                            <label class="item-label">
                                <span class="need_flag">*</span>
                                身份证号：
                                <span class="check-tips"></span>
                            </label>

                            <div class="controls">
                                <input class="input-xlarge focused" id="idCard" name="idCard" type="text" value="${bean.idCard}" required>
                            </div>
                        </div>
                        <div class="form-item cf toggle-director">
                            <label class="item-label">
                                <span class="need_flag">*</span>
                                年龄：
                                <span class="check-tips"></span>
                            </label>

                            <div class="controls">
                                <input class="input-xlarge focused" id="age" name="age" type="number" min="1" max="100" value="${bean.age }" required>
                            </div>
                        </div>
                        <div class="form-item cf toggle-phone">
                            <label class="item-label">
                                <span class="need_flag">*</span>
                                联系电话：
                                <span class="check-tips"></span>
                            </label>
                            <div class="controls">
                                <input class="input-xlarge focused" id="phone" name="phone" type="text" value="${bean.phone }" required>
                            </div>
                        </div>
                        <div class="form-item cf toggle-mobile">
                            <label class="item-label">
                                <span class="need_flag">*</span>
                                手机：
                                <span class="check-tips"></span>
                            </label>

                            <div class="controls">
                                <input class="input-xlarge focused" id="mobile" name="mobile" type="text" value="${bean.mobile }">
                            </div>
                        </div>
                        <div class="form-item cf toggle-email">
                            <label class="item-label">
                                Email：
                                <span class="check-tips"></span>
                            </label>

                            <div class="controls">
                                <input class="input-xlarge focused" id="email" name="email" type="text" value="${bean.email }">
                            </div>
                        </div>
                        <div class="form-item cf toggle-address">
                            <label class="item-label">
                                地址：
                                <span class="check-tips"></span>
                            </label>
                            <div class="controls">
                                <input class="input-xlarge focused" id="address" name="address" type="text" value="${bean.address }">
                            </div>
                        </div>
                        <div class="form-item cf toggle-address">
                            <label class="item-label">
                                邮编：
                                <span class="check-tips"></span>
                            </label>

                            <div class="controls">
                                <input class="input-xlarge focused" id="postcode" name="postcode" type="text" value="${bean.postcode }">
                            </div>
                        </div>
                        <div class="form-item cf toggle-productKeyword">
                            <label class="item-label">
                                <span class="need_flag">*</span>
                                体检机构：
                                <span class="check-tips"></span>
                            </label>

                            <div class="controls">
                                <select id="idInstitution" name="idInstitution" onchange="getProduct()" style="width:200px;" required>
                                    <option value="-1">请选择合作商家</option>
                                    <c:forEach items="${institutionList}" var="inst">
                                        <option value="${inst.id}" <c:if test="${inst.id==bean.idInstitution}">selected="selected"</c:if>  >${inst.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>
                        <div class="form-item cf toggle-productKeyword">
                            <label class="item-label">
                                <span class="need_flag">*</span>
                                套餐名称：
                                <span class="check-tips"></span>
                            </label>

                            <div class="controls">
                                <select id="idProduct" name="idProduct" style="width:200px;" required>
                                    <c:forEach items="${productList}" var="product">
                                        <option value="${product.id}" <c:if test="${product.id==bean.idProduct}">selected="selected"</c:if> >${product.name}</option>
                                    </c:forEach>
                                </select>
                            </div>
                        </div>

                        <div class="form-item cf toggle-productKeyword">
                            <label class="item-label">
                                <span class="need_flag">*</span>
                                性别：
                                <span class="check-tips"></span>
                            </label>

                            <div class="controls">
                                <input type="radio" name="sex" id="sex1" checked value="男"/>男
                                <input type="radio" name="sex" id="sex2" value="女"/>女
                            </div>
                        </div>

                        <div class="form-item cf toggle-productKeyword">
                            <label class="item-label">
                                <span class="need_flag">*</span>
                                报告领取方式：
                                <span class="check-tips"></span>
                            </label>

                            <div class="controls">
                                <input type="radio" name="reportType" id="reportType1" checked value="报告自取"/>报告自取
                                <input type="radio" name="reportType" id="reportType2" value="报告统一回"/>报告统一回
                            </div>
                        </div>

                        <div class="form-item cf toggle-productKeyword">
                            <label class="item-label">
                                <span class="need_flag">*</span>
                                成交价格：
                                <span class="check-tips"></span>
                            </label>

                            <div class="controls">
                                <input class="input-xlarge focused" id="basePrice" name="basePrice" type="text" value="${bean.basePrice }">
                            </div>
                        </div>
                        <div class="form-item cf toggle-productKeyword">
                            <label class="item-label">
                                <span class="need_flag">*</span>
                                付款金额：
                                <span class="check-tips"></span>
                            </label>

                            <div class="controls">
                                <input class="input-xlarge focused" id="salePrice" name="salePrice" type="text" value="${bean.salePrice }">
                            </div>
                        </div>
                        <div class="form-item cf toggle-productKeyword">
                            <label class="item-label">
                                <span class="need_flag">*</span>
                                录单备注：
                                <span class="check-tips"></span>
                            </label>

                            <div class="controls">
                                <input class="input-xlarge focused" id="comment" name="comment" type="text" value="${bean.comment }">
                            </div>
                        </div>
                        <button class="btn" type="button" onclick="checkForm()">确 定</button>
                    </form>
                </div>
            </div>
        </section>
    </div>
</div>
<script language="javascript">
    function checkForm() {
        var buyUser=$("#buyUser").val();
        if(buyUser.trim()==""){
            layer.msg('购买人不能为空!', {icon: 5});
            return false;
        }
        var endUser=$("#endUser").val();
        var age=$("#age").val();
        if(endUser==""){
            layer.msg('体检人姓名不能为空!', {icon: 5});
            return false;
        }
        var idCard=$("#idCard").val();
        if(idCard==""){
            layer.msg('请输入身份证号!', {icon: 5});
            return false;
        }
        if(age=="" || age<0 &&  age>100){
            layer.msg('请输入正确的年龄!', {icon: 5});
            return false;
        }
        var phone=$("#phone").val();
        var mobile=$("#mobile").val();
        if(phone=="" && mobile==""){
            layer.msg('请填写联系电话!', {icon: 5});
            return false;
        }
        var idInstitution = $("#idInstitution").val();
        var idProduct = $("#idProduct").val();
        if(idInstitution==-1){
            layer.msg('请选择合作机构!', {icon: 5});
            return false;
        }
        if(idProduct=="" || idProduct==null){
            layer.msg('请选择合体检套餐!', {icon: 5});
            return false;
        }
        var basePrice = $("#basePrice").val();
        if(basePrice==""){
            layer.msg('成交价格不能为空!', {icon: 5});
            return false;
        }
        var salePrice = $("#salePrice").val();
        if(salePrice==""){
            layer.msg('付款金额不能为空!', {icon: 5});
            return false;
        }


        $('#myForm').ajaxSubmit(function (data) {
            if (data.errno == 1) {
                updateAlert(data.errdesc, 'alert-error');
            } else {
                updateAlert("操作成功！", 'alert-success');
                window.location.href = "${BasePath}/order/order/list?${PublicParams}";
            }
        });
    }


    var groupOrderId = "${bean.id}";
    if (groupOrderId != "") {
        $.getJSON("${BasePath}/order/product/getJSON", {groupOrderId: groupOrderId}, function (data) {
            $.each(data.data, function (InfoIndex, Info) {
                $("#selectedProducts").append('<option value=' + Info.id + '>' + Info.institutionName + "-" + Info.name + '</option>');
            });
        });
    }
    function getProduct() {
        var val = $("#idInstitution").val();
        $("#idProduct option").remove();
        if (val == "-1") {
            return;
        }
        $.getJSON("${BasePath}/order/product/getJSON", {institutionId: val}, function (data) {
            $.each(data.data, function (InfoIndex, Info) {
                $("#idProduct").append('<option value=' + Info.id + '>' + Info.name + '</option>');
            });
        });
    }
    function addPro() {
        var pro = document.getElementById("productId");
        var spro = document.getElementById("selectedProducts");

        if (pro.value != -1 && pro.value != "") {
            for (var i = 0; i < spro.options.length; i++) {
                if (spro.options[i].value == pro.value) {
                    return;
                }
            }
            var option = document.createElement("option");
            spro.options.add(option);
            var insti = document.getElementById("institutionId");
            option.value = pro.value;
            option.innerHTML = pro.options[pro.selectedIndex].text + "-" + insti.options[insti.selectedIndex].text;

        }
    }
    function delPro() {
        var spro = document.getElementById("selectedProducts");
        var oOptions = spro.options;
        for (var i = oOptions.length - 1; i >= 0; i--) {
            if (oOptions[i].selected) spro.remove(i);
        }
    }
    function selectAll() {
        var spro = document.getElementById("selectedProducts");
        var oOptions = spro.options;
        for (var i = oOptions.length - 1; i >= 0; i--) {
            oOptions[i].selected = true;
        }
    }
</script>